package bill.study.concurrency.patterns.producerconsumer.javacip.ch5;

import java.io.File;
import java.io.FileFilter;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class IndexEngine {
	public static void main(String [] args){
		
		File [] files = new File[]{ new File("c:"), new File("d:")};
		
		startIndexing(files);
		
	}
	
	public static void startIndexing(File [] roots){
		BlockingQueue<File> queue = new LinkedBlockingQueue<File>(100);
		FileFilter filter = new FileFilter(){
			public boolean accept(File file){
//				if(file.getAbsolutePath().endsWith("java"))
//				return true;
//				else return false;
				return true;
			}
		};
		
		for(File root: roots){{
			Thread t = new Thread(new FileCrawler(root, filter, queue));
			t.setName("crawler_"+ root.getName());
			t.start();
		}
		}
		
		for(int i = 0; i < 10; i ++){
			Thread t= new Thread(new Indexer(queue));
			t.setName("Indexer_"+ i);
			t.start();
		}
	}

}
